package com.good.jzhouse.dao;

import com.good.jzhouse.bean.Comment;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface CommentDao {

    @Select("select * from Comment")
    @Results({
            @Result(id = true,column = "id" ,property = "id"),
            @Result(column = "content" ,property = "content"),
            @Result(column = "userId",property = "user",one = @One(select = "com.good.jzhouse.dao.UsersDao.selectById")),
            @Result(column = "propertiesId",property = "properties",one = @One(select="com.good.jzhouse.dao.PropertiesDao.selectById")),
            @Result(column = "newsId",property = "news",one = @One(select = "com.good.jzhouse.dao.NewsDao.selectById")),
            @Result(column = "fid",property = "fid"),
            @Result(column = "beginTime",property = "beginTime"),
            @Result(column = "good",property = "good")
    })
    List<Comment> findAll();

    @Select("select * from Comment where id=#{id}")
    @Results({
            @Result(id = true,column = "id" ,property = "id"),
            @Result(column = "content" ,property = "content"),
            @Result(column = "userId",property = "user",one = @One(select = "com.good.jzhouse.dao.UsersDao.selectById")),
            @Result(column = "propertiesId",property = "properties",one = @One(select="com.good.jzhouse.dao.PropertiesDao.selectById")),
            @Result(column = "newsId",property = "news",one = @One(select = "com.good.jzhouse.dao.NewsDao.selectById")),
            @Result(column = "fid",property = "fid"),
            @Result(column = "beginTime",property = "beginTime"),
            @Result(column = "good",property = "good")
    })
    Comment selectById(Integer id);



    @Delete("delete from Comment where id=#{id}")
    int delete(Integer id);

    @Insert("insert into Comment values(#{content},#{user.uid},#{properties.id},#{news.id},#{fid},#{beginTime},#{good})")
    Integer insert(Comment comment);

    @Update("upate Comment set content=#{content},userId=#{user.uid},propertiesId=#{properties.id},newsId=#{news.id},fid=#{fid},beginTime=#{beginTime},good=#{good} where id=#{id} ")
    int update(Comment comment);

    @Select("select count(1) from Comment")
    int selectCount();

}
